// TaskController.java
package com.scuec.groupfive.Controller;

import com.scuec.groupfive.entity.DailyTask;
import com.scuec.groupfive.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/tasks")
public class TaskController {

    @Autowired
    private TaskService taskService;

    // 获取用户今日任务
    @GetMapping("/today")
    public List<DailyTask> getTodayTasks(@RequestParam Long userId) {
        return taskService.getTodayTasks(userId);
    }

    // 添加任务
    @PostMapping
    public int addTask(@RequestBody DailyTask task) {
        return taskService.addTask(task);
    }

    // 更新任务
    @PutMapping
    public int updateTask(@RequestBody DailyTask task) {
        return taskService.updateTask(task);
    }

    // 标记任务完成/未完成
    @PatchMapping("/{taskId}/status")
    public int toggleTaskStatus(@PathVariable Long taskId,
                                @RequestParam Long userId,
                                @RequestParam String status) {
        return taskService.toggleTaskStatus(taskId, userId, status);
    }

    // 删除任务
    @DeleteMapping("/{taskId}")
    public int deleteTask(@PathVariable Long taskId,
                          @RequestParam Long userId) {
        return taskService.deleteTask(taskId, userId);
    }

    // 检查今日任务完成情况
    @GetMapping("/today/status")
    public Map<String, Object> checkTodayTasksStatus(@RequestParam Long userId) {
        return taskService.checkTodayTasksStatus(userId);
    }
}